﻿using Bootstrap.Security;
using CpsyV2Web.DataAccess;
using CpsyV2Web.Models;
using Longbow.Security.Principal;
using System.Collections.Generic;
using System.Data;
using System.Web.Mvc;
using System.Web.Security;
using System.Linq;
using System.Text;

namespace CpsyV2Web.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public class HomeController : Controller
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
       [Authorize]
        public ActionResult Index()
        {
            var v = new IndexModel("~/Home/Index");
            return View(v);
        }
        public ActionResult Person()
       {
           var v = new IndexModel("~/Home/Person");
            return View(v);
       }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public ActionResult Login(string userName, string password, string remember)
        {
            FormsAuthentication.SignOut();
            var mobile = Request.Browser.IsMobileDevice;
            var model = Request.Browser.MobileDeviceModel;
            if (string.IsNullOrEmpty(userName)) return mobile && model != "IPad" ? View("Loginm") : View();
            if (LgbPrincipal.Authenticate(userName, password) || BootstrapUser.Authenticate(userName, password))
            {
                FormsAuthentication.RedirectFromLoginPage(userName, remember == "true");
                return new EmptyResult();
            }
            return mobile && model != "IPad" ? View("Loginm") : View();
        }
    }
}